import csv
import csv
def file_write(list_student: list) -> None:
    with open('exam.csv', 'w', newline='') as csvfile:
        for student in list_student:
            data = ";".join(student) +"\n"
            csvfile.write(data)


def admission(n:int, m:int, students:list):
    list_rezalt_student = [['Фамилия', 'имя', 'результат 1', 'результат 2', 'результат 3', 'сумма'],]
    for student in students:
        list_student = student.split()
        x, y, z = int(list_student[2]),int(list_student[3]),int(list_student[4])
        rezalt = x + y + z
        if x > m and y > m and z> m and  rezalt > n:
            list_rezalt_student.append([list_student[0],list_student[1],list_student[2], list_student[3], list_student[4], str(rezalt)])
    
    return list_rezalt_student

list_rezalt_student = admission(220, 36, ['Хребтов Мартын 70 86 53',
            'Бажанов Сократ 78 91 68',
            'Пушкин Федот 87 35 98',
            'Ульянов Валерий 91 88 75',
            'Сапогов Капитон 68 94 77'])
file_write(list_rezalt_student)

with open('exam.csv', "r", encoding="utf-8") as csvfile:
    reader = [*csv.reader(csvfile, delimiter=";")]
    assert reader == [['Фамилия', 'имя', 'результат 1', 'результат 2', 'результат 3', 'сумма'],
                      ['Бажанов', 'Сократ', '78', '91', '68', '237'],
                      ['Ульянов', 'Валерий', '91', '88', '75', '254'],
                      ['Сапогов', 'Капитон', '68', '94', '77', '239']]